// "Copyright [2021] <Copyright Zhancheng Liang, Shengkai Lin>"

package roce;
import inet.applications.udpapp.UdpBasicApp;

simple RoceAdapter{
    parameters:
        // string interfaceTableModule;   // The path to the InterfaceTable module
        string interfaceTableModule = default("^.interfacetable");
        int localPort = default(1);  // local port (-1: use ephemeral port)
        // string destAddresses = default(""); // list of IP addresses, separated by spaces ("": don't send)
        // string localAddress = default("192.168.0.0");
        int localIdx;
        string packetName = default("UdpBasicAppData");
        // int destPort;
        int destPort = default(1);
        // volatile int messageLength @unit(B); // length of messages to generate, in bytes
        volatile int messageLength @unit(B) = default(0);
        int maxmessageLength = default(65435);
        double startTime @unit(s) = default(this.sendInterval); // application start time (start of the first packet)
        double stopTime @unit(s) = default(-1s);  // time of finishing sending, -1s means forever
        // volatile double sendInterval @unit(s); // should usually be a random value, e.g. exponential(1)
        volatile double sendInterval @unit(s) = default(0);
        int timeToLive = default(-1); // if not -1, set the TTL (IPv4) or Hop Limit (IPv6) field of sent packets to this value
        bool dontFragment = default(false); // if true, asks IP to not fragment the message during routing
        int dscp = default(-1); // if not -1, set the DSCP field (on IPv4/IPv6) of sent packets to this value
        int tos = default(-1); // if not -1, set the Type Of Service (IPv4) / Traffic Class (IPv6) field of sent packets to this value
        string multicastInterface = default("");  // if not empty, set the multicast output interface option on the socket (interface name expected)
        bool receiveBroadcast = default(false); // if true, makes the socket receive broadcast packets
        // bool joinLocalMulticastGroups = default(false); // if true, makes the socket receive packets from all multicast groups set on local interfaces
        bool joinLocalMulticastGroups = default(false);
        @display("i=block/app");
        @lifecycleSupport;
        double stopOperationExtraTime @unit(s) = default(-1s);    // extra time after lifecycle stop operation finished
        double stopOperationTimeout @unit(s) = default(2s);    // timeout value for lifecycle stop operation
        @signal[packetSent](type=inet::Packet);
        @signal[packetReceived](type=inet::Packet);
        @statistic[packetReceived](title="packets received"; source=packetReceived; record=count,"sum(packetBytes)","vector(packetBytes)"; interpolationmode=none);
        @statistic[throughput](title="throughput"; unit=bps; source="throughput(packetReceived)"; record=vector);
        @statistic[packetSent](title="packets sent"; source=packetSent; record=count,"sum(packetBytes)","vector(packetBytes)"; interpolationmode=none);
        @statistic[rcvdPkLifetime](title="received packet lifetime"; source="dataAge(packetReceived)"; unit=s; record=stats,vector; interpolationmode=none);
        @statistic[rcvdPkSeqNo](title="received packet sequence number"; source="appPkSeqNo(packetReceived)"; record=vector; interpolationmode=none);
        int roceType = default(1);
    gates:
        input socketIn @labels(UdpControlInfo/up);
        output socketOut @labels(UdpControlInfo/down);

        inout gpu_port;
}